﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Liquid.Collections;

namespace GapBufferTests {
	/// <summary>
	/// Summary description for UnitTest1
	/// </summary>
	[TestClass]
	public class Constructors {
		public TestContext TestContext { get; set; }

		[TestMethod]
		public void CreateDefault() {
			var buffer = new GapBuffer<int>();
			Assert.IsTrue(buffer.Count == 0);
			Assert.IsTrue(buffer.Capacity > 0);
		}

		[TestMethod]
		public void CreateWithCapacity() {
			var buffer = new GapBuffer<int>(256);
			Assert.AreEqual(0, buffer.Count);
			Assert.AreEqual(256, buffer.Capacity);
		}

		[TestMethod]
		public void CreateFromFilledArray() {
			var buffer = GapBuffer<int>.FromArray(new int[] { 1, 2, 3, 4 });
			Assert.AreEqual(4, buffer.Count);
			Assert.AreEqual(4, buffer.Capacity);
			Assert.IsTrue(buffer.ToArray().SequenceEqual(new int[] { 1, 2, 3, 4 }));
		}

		[TestMethod]
		public void CreateFromGappedArray() {
			var buffer = GapBuffer<int>.FromArray(new int[] { 1, 2, 3, 4 }, 1, 2);
			Assert.AreEqual(2, buffer.Count);
			Assert.AreEqual(4, buffer.Capacity);
			Assert.IsTrue(buffer.ToArray().SequenceEqual(new int[] { 1, 4 }));
		}
	}
}
